package yuhuibear.poat.object.mapEntity;

import yuhuibear.poat.annotations.relation.View;
import yuhuibear.poat.object.bean.BeanStruct;
import yuhuibear.poat.util.NameConvertor;

public class ViewTask extends SqlTask {

	private static int viewCnt = 0;

	private final static String head = "CREATE OR REPLACE VIEW ";

	public ViewTask(BeanStruct bean, View view) {
		init(view.name(), MapEntityTask.Type.View, bean.getType().toString(), bean, head
				+ view.name() + " as  " + view.sqlToCreate());
		refs.addAll(NameConvertor.extractEntityName(view.sqlToCreate()));
		ViewTask.viewCnt++;
		SqlTask.register();
	}

	public static int viewCount() {
		return viewCnt;
	}

	public void done() {
		done = true;
		ViewTask.viewCnt--;
		SqlTask.unRegister();
	}

}
